package com.ubi.core.framework.response;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * 内部类，对ServletOutputStream进行包装
 * <p/>
 * TODO(KENT) 考虑优化掉，去掉这个类
 */
public class WapperedOutputStream extends ServletOutputStream {

    private ByteArrayOutputStream bos = null;

    public ByteArrayOutputStream getBos() {
        return bos;
    }

    public void setBos(ByteArrayOutputStream bos) {
        this.bos = bos;
    }

    public WapperedOutputStream(ByteArrayOutputStream stream) throws IOException {
        bos = stream;
    }

    @Override
    public void write(int b) throws IOException {
        bos.write(b);
    }

    @Override
    public void write(byte[] b) throws IOException {
        bos.write(b, 0, b.length);
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }
}